package siniestro.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import siniestro.entities.Siniestro;

public class SiniestroDaoImpl {

	public Siniestro save(Siniestro siniestro) {
		EntityManagerFactory emf = EMF.get();
		EntityManager em = emf.createEntityManager();
		em.getTransaction().begin();
		em.persist(siniestro);
		em.getTransaction().commit();
		em.close();
		return siniestro;
	}

	public List<Siniestro> getAll() {
		EntityManagerFactory emf = EMF.get();
		EntityManager em = emf.createEntityManager();

	    String query = "select from " + Siniestro.class.getName() + " s ORDER BY s.fecha";
	    List<Siniestro> siniestros= (List<Siniestro>) em.createQuery(query).getResultList();
		em.close();
		return siniestros;
	}

}
